/***************************************************************************
 *   Copyright (C) 2008 by Thomas Fannes                                   *
 *   thomasfannes@gmail.com                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOARDTILEDESCRIPTION_H
#define BOARDTILEDESCRIPTION_H

#include <QDataStream>
#include "HexVector.h"

namespace board
{
	enum TileResource
	{
		TileResourceUndefined = 0, TileResourceBrick = 1, TileResourceGrain = 2, TileResourceOre = 3, TileResourceWood = 4, TileResourceWool = 5, TilResourceGeneric = 6,
	};

	enum TileType
	{
		TileTypeUndefined = 0, TileTypeLand = 1, TileTypeSea = 2
	};

	enum TileNumber
	{
		TileNumberUndefined = 0,
		TileNumber2 = 1,
		TileNumber3 = 2,
		TileNumber4 = 3,
		TileNumber5 = 4,
		TileNumber6 = 5,
		TileNumber8 = 6,
		TileNumber9 = 7,
		TileNumber10 = 8,
		TileNumber11 = 9,
		TileNumber12 = 10
	};

	enum TileOrientation
	{
		TileOrientationUndefined = 0, TileOrientation12H = 1, TileOrientation2H = 2, TileOrientation4H = 3, TileOrientation6H = 4, TileOrientation8H = 5, TileOrientation10H = 6
	};

	struct TileData
	{
	public:
		TileData() :
			type(TileTypeUndefined), number(TileNumberUndefined), resource(TileResourceUndefined), orientation(TileOrientationUndefined)
		{
		};

		TileData(TileType iType, TileNumber iNumber, TileResource iResource, TileOrientation iOrientation) :
			type(iType), number(iNumber), resource(iResource), orientation(iOrientation)
		{
		};


		TileType type;
		TileNumber number;
		TileResource resource;
		TileOrientation orientation;

		friend QDataStream & operator<<(QDataStream & stream, const TileData & data)
		{
			return stream << (qint32)data.type << (qint32)data.number << (qint32)data.resource << (qint32)data.orientation;
		};
		friend QDataStream & operator>>(QDataStream & stream, TileData & data)
		{
			qint32 iType, iNumber, iResource, iOrientation;

			stream >> iType >> iNumber >> iResource >> iOrientation;

			data.type = (TileType)iType;
			data.number = (TileNumber)iNumber;
			data.resource = (TileResource)iResource;
			data.orientation = (TileOrientation)iOrientation;

			return stream;
		};
	};

	class TileDescription
	{
		friend QDataStream & operator<<(QDataStream & stream, const TileDescription & desc)
		{
			return stream << desc.position << desc.data;
		};
		friend QDataStream & operator>>(QDataStream & stream, TileDescription & desc)
		{
			return stream >> desc.position >> desc.data;
		}

	public:
		structure::HexVector position;
		TileData data;

	};
}

#endif
